fix: serialize model-backed rollout interruptions as dicts#3790
Merged
seratch merged 1 commit intoJul 10, 2026
Merged
Conversation
`build_rollout_payload` passed a `ToolApprovalItem.raw_item` pydantic model straight into `_to_dump_compatible`, which has no BaseModel branch. Because pydantic v2 models are iterable, the model fell into the generic `Iterable` branch and was serialized as a list of `[key, value]` pairs instead of a JSON object, corrupting persisted interrupted-run rollouts. Model raw items are now `model_dump`-ed before normalization, matching the convention in `run_state._serialize_tool_input`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Anyone using sandbox rollout memory with human-in-the-loop tool approval (
Runnerruns that get interrupted for approval) hits silent data corruption when the rollout is persisted.build_rollout_payloadserializes each interruption by passingToolApprovalItem.raw_itemstraight into_to_dump_compatible. For an interrupted tool call,raw_itemis a pydantic model (ResponseFunctionToolCall,McpCall,LocalShellCall, etc.)._to_dump_compatiblehas noBaseModelbranch, and because pydantic v2 models are iterable (they yield(key, value)tuples), the model falls into the genericIterablebranch and is turned into a list of[key, value]pairs instead of a JSON object. Every other rollout section (input,generated_items) is pre-converted to dicts, so only the interruptions path passes a raw model through.The fix
model_dumps a model raw item before normalization, matching the existing convention inrun_state._serialize_tool_input(dump first, then_to_dump_compatible). dict and other raw items are unchanged.Before/after with the public API:
Test plan
Added
test_build_rollout_payload_serializes_model_interruptions_as_dictsintests/sandbox/test_memory.py, asserting the serialized interruption is adictequal toraw_item.model_dump(exclude_unset=True). Verified it passes with the fix and fails onupstream/main(the interruption comes back as a list of[key, value]pairs).ruff formatandruff checkare clean on both changed files.Issue number
Checks
.agents/skills/code-change-verification/scripts/run.sh